package com.infore.dao.impl;

import com.infore.dao.UserDao;
import com.infore.entity.User;
import org.hibernate.Criteria;
import org.hibernate.SQLQuery;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author:wk
 * @date:Created in 15:54 2017\11\21 0021
 */
@Repository
public class UserDaoImpl implements UserDao {

    @Autowired
    private SessionFactory sessionFactory;

    public List<User> findAll() {
        Criteria criteria = sessionFactory.getCurrentSession().createCriteria(User.class);
        return criteria.list();
    }

    public List<User> findAll1() {
        String hql = "select ID \"id\",XM \"name\" from XT_YHXX";
        SQLQuery query = sessionFactory.getCurrentSession().createSQLQuery(hql).addEntity(User.class);
        return query.list();
    }
}
